package thread;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class SwapPrint {

    private ReentrantLock rl = new ReentrantLock();
    private Condition condition = rl.newCondition();

    public void printNumber(int i) {
        try {
            rl.lock();
            condition.signal();
            System.out.println(Thread.currentThread().getName() + " " + i);
            condition.await();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            rl.unlock();
        }
    }
}
